let server = null;
let io = null;
let queue = [];

module.exports = {
	init(app) {
		if (!server) {
			server = require('http').createServer(app);
			io = require('socket.io').listen(server);
			io.on('connection', function () {
				io.sockets.emit("status", {running: queue.length > 0, stack: queue});
			});
			server.listen(3000);
		}
	},
	get() {
		return server;
	},
	add(info) {
		queue = queue.concat((info + "").split("\n"));
		io.sockets.emit("status", {running: true, stack: queue});
	},
	done(isSuccess) {
		queue = [];
		io.sockets.emit("status", {done: isSuccess, running: false, stack: []});
	}
};